<template>
  <div>
    <page-main :title="news.type">
      <el-row>
        <div style="text-align: center;"><h2>{{news.title}}</h2></div>
      </el-row>
      <el-row type="flex" justify="center">
        <el-col :span="4"></el-col>
        <el-col :span="6">
          <div>
            发布时间：{{news.issuedate}}
          </div>
        </el-col>
        <el-col :span="6">
          <div>
            点击人数：{{news.access}}
          </div>
        </el-col>
      </el-row>
      <br>
      <br>
      <br>
      <br>
      <el-row>
        <el-col :span="2"><br></el-col>
        <el-col :span="18">
          <div v-html="news.content" class="contentView"></div>
        </el-col>
        <el-col :span="2"><br></el-col>
      </el-row>
    </page-main>
  </div>
</template>

<script>
export default {
    name: 'news_view',
    data() {
      return {
        news: {}
      }
    },
    created() {

    },
    beforeRouteEnter(to, from, next) {
        let that = this
        next(vm => {
            // 通过 `vm` 访问fetchData，将query参数name，传递过去，进行逻辑处理
            // that.type = vm.$route.params.type
            vm.fetchData(vm.$route.params.type, vm.$route.params.id);
        });
    },
    methods: {
        fetchData(type, id) {
            this.id = id
            if (id != '*') {
                this.$util.post('public/selectNewsByPrimaryKey', {id: id}).then(res => {
                    this.news = res
                    this.news.access++;
                    this.$util.post('public/updateNewsByPrimaryKey', this.news).then(res => {

                    })
                })
            }
        },
    }
}
</script>
